package com.yz.newspaper.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yz.newspaper.mapper.IllustratedMapper;
import com.yz.newspaper.mapper.WithVideoMapper;
import com.yz.newspaper.pojo.po.Illustrated;
import com.yz.newspaper.pojo.po.LiteratureType;
import com.yz.newspaper.pojo.po.WithVideo;
import com.yz.newspaper.pojo.result.Result;
import com.yz.newspaper.service.ILiteratureTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 *体裁类型
 * @author author
 * @since 2024-04-21
 */
@RestController
@RequestMapping("/literature")
public class LiteratureTypeController {

    @Autowired
    private ILiteratureTypeService literatureTypeService;
    @Autowired
    private IllustratedMapper illustratedMapper;
    @Autowired
    private WithVideoMapper withVideoMapper;

    @GetMapping("/all")
    @ApiOperation("查询所有体裁类型")
    public Result<Map<Integer, List<LiteratureType>>> getLiteratureTypes() {

        Map<Integer, List<LiteratureType>> literatureTypes = literatureTypeService.getLiteratureTypes();

        return Result.success(literatureTypes);
    }

    @GetMapping("/byMedia")
    @ApiOperation("根据媒体类型查询体裁类型")
    public Result<List<LiteratureType>> getLiteratureTypesByMedia(String media) {

        List<LiteratureType> literatureTypes = literatureTypeService.getLiteratureTypesByMedia(media);
        return Result.success(literatureTypes);
    }

    @ApiOperation("根据媒体查询配图信息")
    @GetMapping("/illustrated/byMedia")
    public Result<List<Illustrated>> getIllustratedByMedia(String media){
        List<Illustrated> illustrateds = illustratedMapper.selectList(new LambdaQueryWrapper<Illustrated>()
                .eq(Illustrated::getMedia, media));
        return Result.success(illustrateds);
    }
    @ApiOperation("根据媒体查询配视频信息")
    @GetMapping("/withVideo/byMedia")
    public Result<List<WithVideo>> getWithVideo(String media){
        List<WithVideo> withVideos = withVideoMapper.selectList(new LambdaQueryWrapper<WithVideo>()
                .eq(WithVideo::getMedia, media));
        return Result.success(withVideos);
    }

}
